{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6d6a43f2-ea6f-4b82-93e7-a1f3cc36116d",
   "metadata": {},
   "source": [
    "查看类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "7b64cf45-202f-4c7d-9b53-d2b6a70f0d09",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "int"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(12)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ae0f3f06-bdad-420e-92c2-fc2743f4ee7e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "float"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(1.23)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "de0f617b-412e-498f-987f-2f8e9fa2fc19",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "str"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type('abc')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "9eae6716-042a-4a30-a42c-49f205d3fba3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "bool"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e5ff47e3-401b-42c2-9f42-a60f6cfe7799",
   "metadata": {},
   "source": [
    "## 转换成整数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "447afd4e-f34c-438d-ae83-8feeae485028",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "123"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "int('123')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "363b1595-326e-4f47-a0c2-d4444562dd9c",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "invalid literal for int() with base 10: '123.45'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[12], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;43mint\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m123.45\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n",
      "\u001b[0;31mValueError\u001b[0m: invalid literal for int() with base 10: '123.45'"
     ]
    }
   ],
   "source": [
    "int('123.45')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "c0661bd8-f0c3-4f87-a32a-fbef95250d6b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "int(12.54)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bb50a5d1-cb4d-47d5-9016-66538c7e3a24",
   "metadata": {},
   "source": [
    "## 转换成浮点"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "2eb43b6d-a949-4a54-a2d2-0e03aed5ee0c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "123.0"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "float('123')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "8eba0cff-7c2d-4283-8f39-74898791c7d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "123.45"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "float('123.45')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "baf8313c-8edf-4066-bded-ad3951ce0c9a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12.345"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "float('1.2345e+1')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "6b14e9bb-2b81-4539-9b0a-324eb39713eb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "123.0"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "float(123)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5e72e689-3fd2-4c24-849b-c16110504051",
   "metadata": {},
   "source": [
    "## 转换成字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "63e0cefe-299a-4dc7-9e6c-ba4f5b5ecbad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'0.123'"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str(0.123)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "f73377fd-9ab7-4089-8609-d79687936140",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'0.3333333333333333'"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str(1/3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "42a5dca1-29db-4a29-bf47-f43d1011572a",
   "metadata": {},
   "source": [
    "## 与布尔类型相关的转换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "f70d8b0b-4886-43a6-8a48-7d117ed5a0ef",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "int(True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "f2221a64-53b4-4add-8412-e0a5e6135316",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "int(False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "edb16d39-324f-4b8a-9c0d-0e6a8d3252e0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "float(True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "31a402cc-dbf3-47b6-989d-7778d36bf409",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "float(False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "277caae9-452e-4eca-8109-f5145e7ac6e6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'True'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str(True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "12dd4c98-a08a-4055-aeb1-20a60e53efe9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'False'"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str(False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "3741f136-bc38-4931-92a3-8f3e4c6c2876",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bool(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "6ca3b8e0-7cb5-4e21-ace3-9dbf4b5dc45b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bool('')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
